VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "TestFineMethodCaller"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private mHolder As ObjectHolder
Private mCaller As FineMethodCaller
Private mHandler As MethodErrorHandler
Private mCalled As Boolean
Private mRaise As Boolean
Private mError As Integer
''Private mStandardFactory As New ProjectFactory
Private mProjectFactory As New ProjectFactory
Private mNotify As New MockNotifier
Private mAdapter As New MethodCallerAdapter
Private mErrorCollection As Collection

Public Sub testCreation()
givenFineMethodCaller
thenNotCalled
thenTimeIs0
thenNoErrors
End Sub
Public Sub testCallMethod()
givenFineMethodCaller
whenCalled
thenCalled
thenTimeGT0
thenNoErrors
End Sub
Public Sub testCallMethodWithError()
givenFineMethodCaller
whenCalledWithError
thenCalled
thenTimeGT0
thenErrorNumberIs 1001
End Sub
Public Sub testCallMethodWithErrorNoHandler()
givenCallerWrappedInErrorHandler
whenWrapperCalledWithError
thenCalled
thenTimeGT0
thenErrorNumberIs 1001
thenWrapperCaughtError
End Sub


''
''
Private Sub givenFineMethodCaller()
Set mHolder = New ObjectHolder
Set mErrorCollection = New Collection
Set mCaller = mProjectFactory.newFineMethodCaller(mHolder, "forward")
End Sub
Private Sub givenCallerWrappedInErrorHandler()
'Note
'We're overriding the usual factory!!!
'Set mFactory = mAltFactory

''givenFineMethodCaller
Set mHolder = New ObjectHolder
Set mErrorCollection = New Collection
Set mCaller = mProjectFactory.newFineMethodCallerAlt(mHolder, "forward")

Set mHandler = New MethodErrorHandler
mHandler.init mCaller, Me, Me
End Sub


Private Sub whenCalled()
mHolder.object = Me
mCaller.forward mNotify
End Sub
Private Sub whenCalledWithError()
mRaise = True
whenCalled
End Sub
Private Sub whenWrapperCalledWithError()
mRaise = True
mHolder.object = Me
'Override mHandler init
mAdapter.init mCaller, mNotify
mHandler.init mAdapter, Me, Me
mHandler.forward
End Sub


Private Sub thenNotCalled()
assert.isFalse mCalled, "Not Called"
End Sub
Private Sub thenCalled()
assert.isTrue mCalled, "Called"
End Sub
Private Sub thenTimeIs0()
assert.equals mCaller.elapsedTime, 0, "Time should be 0"
End Sub
Private Sub thenTimeGT0()
assert.isTrue mCaller.elapsedTime > 0, "Time should be >0"
End Sub
Private Sub thenErrorNumberIs(number As Integer)
assert.equals mCaller.errorInfo.number, number, "Error should be" + Str(number)
End Sub
Private Sub thenNoErrors()
assert.equals mErrorCollection.Count, 0, "No errors"
End Sub


Private Sub thenWrapperCaughtError()
assert.equals mError, 1002, "My Error number should be 1002"
End Sub


''
'forwarded call
Public Sub forward()
mCalled = True
If mRaise Then
    Err.Raise 1001
End If
End Sub

Public Sub handleError()
mError = Err.number
'TODO
'log the rest of the members of Err
End Sub

'OPTIONAL METHODS
Public Sub setup()
mCalled = False
mRaise = False
'Set mFactory = mStandardFactory
'mAltFactory.init mStandardFactory
End Sub
Public Function NumOfAsserts() As Long
NumOfAsserts = 13
End Function

